package cn.lxm.samples.auth_server.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @author LXM
 * @Title: oauth
 * @Description:OAuth2.0使用数据库存储Token、Client、授权信息等。本配置为ClientDetailService提供JDBC的数据源
 * @date 2018/8/8上午11:48
 */

@Configuration
@PropertySource("classpath:sso_config.properties")
public class DataSourceConfig {

    /**
     * OAuth的数据库配置信息，用于存储Client Details，避免进程结束后客户端信息丢失
     *
     * @return
     */
    @Bean(name = "oauthDataSource")
    @ConfigurationProperties(prefix = "spring.oauth.datasource")
    public DataSource oauthDataSource() {
        return DataSourceBuilder.create().build();
    }


    /**
     * 默认的DataSource
     *
     * @return
     */
    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

}